package com.kfm.am;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringTest03 {

    public static void main(String[] args) {
        String str = "123456";
//        pattern(str);
        matcher(str);

    }

    public static void pattern(String str) {
        String regex = "\\d{4}";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        while (matcher.find()) {
            System.out.println(matcher.group());
        }
    }

    public static void matcher(String str) {
        String regex = "\\d{4}";
        Pattern pattern = Pattern.compile(regex); // 将正则编译成 pattern 对象
        Matcher matcher = pattern.matcher(str); // 对象加载字符串
        System.out.println("find===" + matcher.find());
        boolean matches = matcher.matches(); // 用匹配规则去匹配字符串
        System.out.println(matches);
    }

}
